﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SkillSystem;
using CharacterSystem;
using System;

public class CharacterCtrl : CharacterBase
{
    /// <summary>技能间隔已过去的时间</summary>
    public float time;
    /// <summary>技能之间的间隔</summary>
    public float WaitTime = 0.15f;
    /// <summary>敲击数</summary>
    public int HitCount;
    public float Speed = 1;

    Transform cameraTrans;
    Dictionary<float, List<SkillItemData>> SkillList = new Dictionary<float, List<SkillItemData>>() {  };

    //{ 1,new List<SkillItemInfo>() {
    //                                                                                                        new SkillItemInfo(1,"G_LP","Attack 1",0) ,
    //                                                                                                        new SkillItemInfo(1,"G_RP","Attack 2",1) ,
    //                                                                                                        new SkillItemInfo(1,"G_SpinJRK","Attack 3",2) ,
    //                                                                                                   } }

    

    private SkillAnimationProcesser player1;
    private SkillAnimationProcesser player2;


    void Start () {
        SkillSystemFacade.Inst.Init();
        ActiveSkillTransmitters.Add( 2,new ComboSkillTransmit(SkillSystemFacade.Inst.GetSkillDataByID(2), CharacterAnimator));
        ActiveSkillTransmitters.Add(3, new ActiveSkillTransmitter(SkillSystemFacade.Inst.GetSkillDataByID(3), CharacterAnimator));

        player1 = (SkillAnimationProcesser)ActiveSkillTransmitters[2].SkillProcessers[SkillProcesserType.Animation];
        player2 = (SkillAnimationProcesser)ActiveSkillTransmitters[3].SkillProcessers[SkillProcesserType.Animation];

        cameraTrans = CameraSystem.CameraSystemFacade.Inst.GetCamera(CameraSystem.CameraType.Main).CameraTrans;
    }
	
	void Update () {
        Vector3 speedDir=Vector3.zero;

        if (Input.GetKeyDown(KeyCode.J))
        {
            ActiveSkillTransmitters[2].StartTransmit();
            CharacterAnimator.SetInteger("State", 0);
        }

        if (Input.GetKeyDown(KeyCode.K))
        {
            ActiveSkillTransmitters[3].StartTransmit();
            CharacterAnimator.SetInteger("State", 0);
        }
        if (Input.GetKey(KeyCode.W))
        {
        }
            
        if(ActiveSkillTransmitters[2].CurSkillState==SkillState.End)
        {
            if (Input.GetKey(KeyCode.W))
            {
                speedDir += this.cameraTrans.forward;
            }
            if (Input.GetKey(KeyCode.S))
            {
                speedDir += -this.cameraTrans.forward;
            }
            if (Input.GetKey(KeyCode.A))
            {
                speedDir += -this.cameraTrans.right;
            }
            if (Input.GetKey(KeyCode.D))
            {
                speedDir += this.cameraTrans.right;
            }

            if (speedDir == Vector3.zero)
            {
                CharacterAnimator.SetInteger("State", 0);
            }
            else
            {
                CharacterAnimator.SetInteger("State", 1);
                //Debug.Break();

            }
        }
        MoveTo(speedDir+transform.position );


        CharacterAnimator.speed = Speed;

        time += Time.deltaTime;
        if (time>= WaitTime)
        {
            time = 0;
        }
        else
        {

        }

    }

    public void AnimationStart(AnimationEvent data)
    {
        player1.AnimationStart(data);
        player2.AnimationStart(data);
    }

    public void OnAnimatorMove()
    {
        
    }

    public void AnimationEnd(AnimationEvent data)
    {
        player1.AnimationEnd(data);
        player2.AnimationEnd(data);

    }
}
